Fix #6229: @ConstructorProperties must not be gated by DETECT_PARAMETER_NAMES - #6230
Conversation
MapperFeature.DETECT_PARAMETER_NAMES (added in FasterXML#5314) is meant to control only the bytecode-derived (-parameters) implicit parameter name detection merged into core in Jackson 3. JacksonAnnotationIntrospector .findImplicitPropertyName() had a single early-return gated on that flag sitting above both the @ConstructorProperties lookup and the bytecode lookup, so disabling the flag silently broke @ConstructorProperties-based Creator detection as well, even though that mechanism predates and is independent of -parameters compilation and worked regardless of it in Jackson 2. Scopes the DETECT_PARAMETER_NAMES check to only the two bytecode-based branches, leaving @ConstructorProperties resolution unconditional.
|
@cowtowncoder Signed SLA sent! lmk if anything else is required |
Code Review ✅ Approved🟡 Medium risk · Constructor-property creator detection now works regardless of bytecode-name detection settings. Fixes OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
|
Thank you, @mauriciocsz ! |
Fixes #6229.
MapperFeature.DETECT_PARAMETER_NAMES(added in #5314) is meant to control only the bytecode-derived (-parameters) implicit parameter name detection that Jackson 3 merged in from the oldjackson-parameter-namesmodule. Per its own Javadoc, disabling it should "restore the older Jackson 2.x behavior" — but Jackson 2 always supported@ConstructorPropertiesindependently of that module.JacksonAnnotationIntrospector.findImplicitPropertyName()had a single early-return gated onDETECT_PARAMETER_NAMESsitting above both the@ConstructorPropertieslookup and the bytecode lookup, so disabling the flag broke both instead of just the bytecode one.This PR moves the
DETECT_PARAMETER_NAMEScheck down so it only gates the bytecode-based fallback (_findImplicitName), leaving the@ConstructorProperties-based lookup (_javaBeansHelper.findConstructorName) unconditional, matching both the feature's documented intent and Jackson 2 parity.Changes
src/main/java/tools/jackson/databind/introspect/JacksonAnnotationIntrospector.java: scoped theDETECT_PARAMETER_NAMEScheck to only the two bytecode-based branches (constructor parameter fallback, static factory-method parameter detection);@ConstructorPropertiesresolution no longer short-circuits. Extracted the check into adetectParamNameslocal (matches this codebase's existing convention for caching aMapperFeaturecheck).src/test/java/tools/jackson/databind/deser/WithoutParamNamesModule5314Test.java: extended the existingDETECT_PARAMETER_NAMEStest file (rather than adding a new one) withCtorPropsBean178— a bean matchingBean178's shape but with@ConstructorPropertiesadded — and a new test,testConstructorPropertiesIgnoresDetectParameterNames, verifying it deserializes successfully under all three configstestWorksByDefaultalready exercises (enabled, disabled,Jackson2Defaults).Testing
Both tests pass (1 pre-existing + 1 new). Locally reverted just the
JacksonAnnotationIntrospectorchange (keeping the new test) to confirm the new test fails against pre-fix code with the exactInvalidDefinitionExceptionfrom #6229 ("has no property name ... cannot use as property-based Creator"), then passes again with the fix restored.No other tests were touched; the change is scoped to the one method.